﻿using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Grauers_set_metadata_properties.Grauers
{
    public class General
    {
        public static void RemoveEventReceiver(string listName)
        {
            SPList list = SPContext.Current.Web.Lists[listName];
            if (list != null)
            {
                //SPEventReceiverDefinitionCollection ercCollection = list.EventReceivers;
                List<Guid> toDelete = new List<Guid>();
                foreach (SPEventReceiverDefinition erd in list.EventReceivers)
                {
                    if (erd.Class == "Grauers_set_metadata_properties.Grauers_metadata_properties_handler.Grauers_metadata_properties_handler")
                    {
                        toDelete.Add(erd.Id);
                    }
                }

                foreach (Guid id in toDelete)
                {
                    list.EventReceivers[id].Delete();
                }

                list.Update();
            }
        }
    }
}
